package com.llmops.core;

import lombok.Data;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

@Data
public class Edge {
    private static final Logger logger = LoggerFactory.getLogger(Edge.class);

    public enum ConditionType {
        EQUAL,
        CONTAINS
    }

    private ConditionType conditionType;
    private Object conditionValue;
    private String sourceId;
    private String targetId;

    public Edge(String sourceId, String targetId,ConditionType conditionType,Object conditionValue) {
        this.sourceId = sourceId;
        this.targetId = targetId;
        this.conditionType = conditionType;
        this.conditionValue = conditionValue;
    }

    public Edge(String sourceId, String targetId) {
        this.sourceId = sourceId;
        this.targetId = targetId;
    }

    public boolean evaluateCondition(Context context) {
        if (conditionType == null) return true;
        
        Object actualValue = context.getVariable(sourceId + "_output");
        if (actualValue == null) return false;
        logger.info(String.format("{}---{},conditionType=%s,conditionValue=%s,conditionType=%s",sourceId,targetId,conditionType,conditionValue,actualValue));
        switch (conditionType) {
            case EQUAL:
                return actualValue.toString().equals(conditionValue.toString());
            case CONTAINS:
                return actualValue.toString().contains(conditionValue.toString());
            default:
                return false;
        }
    }
}